package group6renderer;

import group6renderer.renderernode.*;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;

/**
 *
 * @author Yiannis
 */
public class Renderer implements Visitor
{

    //private TreeNode node;
    
    private TreeNode root;
    private Display display;
    
    Renderer(TreeNode node)
    {
    	root = node;
    }


    public void render(TreeNode node, Display theDisplay)
    {
    	display = theDisplay;
		int i = 0;
		node.accept(this);
	
	
		while ((!node.isLeaf() && i < node.getChildrenNum()) && !(node instanceof TableCellNode))
		{
			render(node.getChild(i), theDisplay);
	    	i++;
		}
		if (!(node instanceof TableCellNode) && ((node instanceof FormatNode) || (node instanceof BranchNode)))
		{
		node.accept(this);
		}
    }
    
    public void renderTable(TableCellNode node, Display theDisplay)
    {
    	display = theDisplay;
    	int i = 0;
	
    	while (i < node.getChildrenNum())
    	{
    		render(node.getChild(i), theDisplay);
	  	 i++;
    	}
    }
    
    public Display getDisplay()
    {
    	return display;
    }


    public void visit(TreeNode node)
    {
    	node.drawNode(display);
    }

}
